<%@page import="data.PageConfig" import="java.util.ArrayList"
	import="data.Rmi" import="bean.Patient" import="bean.Ordonnance"
	import="bean.Medecin" import="bean.Prescription"
	import="bean.Medicament" import="com.itextpdf.*"
	import="java.util.Date" import="com.itextpdf.text.Document"
	import="org.apache.commons.fileupload.*"
	import="data.*"
	import="java.io.*"
	import="com.itextpdf.text.*"
	import="com.itextpdf.text.pdf.*"
%>

<jsp:useBean id="manager" scope="session" class="manager.Manager"></jsp:useBean>

<%
	boolean error = false;
	String nom = "";
	String prenom = "";
	Ordonnance ordonnance = null;
	Medecin medecin = null;
	Patient patient = null;

	ArrayList<Prescription> listePrescription = null;
	if (request.getParameter("consulterOrdonnance") != null) {
		int idOrdonnance = Integer.parseInt(request
				.getParameter("idOrdonnance"));
		ordonnance = manager.getListOrdonnance().get(idOrdonnance);
		medecin = Rmi.getMedecin(ordonnance.getIdMedecin());
		patient = Rmi.getPatient(ordonnance.getIdPatient());
		listePrescription = Rmi.recherchePrescription(
				ordonnance.getId(), 0, 100);
	}

	ArrayList<String> messages = manager.extraireMessages();
	if (messages.size() > 0) {
		out.println("<div class=\"notif-erreur\">");
		out.println("<ul>");
		for (int i = 0; i < messages.size(); i++) {
			out.println("<li>" + messages.get(i) + "</li>");
		}
		out.println("</ul>");
		out.println("</div>");
	}
	
	//generation du document pdf
	String chemin ="./ordonnance.pdf";	
	File fichier = new File(chemin);
	Document document = new Document();
	PdfWriter.getInstance(document, new FileOutputStream(fichier));
	document.open();
	document.add(new Paragraph("Helloooo"));
	document.close();
	
	
	//contenu de la page web
	out.println("<div>");
	out.println("<tr><td><form action=\"../../ServletPDF\" method=\"post\">");
	
	out.println("<table>");	
	out.println("<tr><td>Date : "+ordonnance.getDate()+"</td></tr>");
	out.println("<tr><td>Patient : "+ patient.getPrenom() + " "
		+ patient.getNom()+"</td></tr>");
	out.println("<tr><td>Medecin : "+ medecin.getPrenom() + " "
			+ medecin.getNom()+"</td></tr>");

	out.print("<input type=\"hidden\" name=\"medecin\" value=\""+medecin.getNom()+" "+medecin.getPrenom()+"\" />");
	out.print("<input type=\"hidden\" name=\"date\" value=\""+ordonnance.getDate()+"\" />");
	out.print("<input type=\"hidden\" name=\"patient\" value=\""+patient.getNom()+" "+patient.getPrenom()+"\" />");
	out.print("<input type=\"hidden\" name=\"idOrdonnance\" value=\""+ordonnance.getId()+"\" />");
	
	for (Prescription prescription : listePrescription) {
		Medicament medoc = Rmi.getMedicament(prescription
				.getIdMedicament());
		out.println("<tr><td>Medicament : " + medoc.getNom() + " Posologie :"
				+ prescription.getPosologie()+"</td></tr>");
	}
	
	out.println("<input type=\"submit\" name=\"Telecharger\" value=\"Telecharger\" /></form></td></tr>");

	out.println("</table>");	
	out.println("</form>");
	out.println("</div>");
	
	
%>

